import axios from "axios";


const service = axios.create({
  baseURL: import.meta.env.VITE_BASE_API,
  timeout: 5000
});

// 请求拦截器
service.interceptors.request.use((config) => {
  // 添加 icode
  config.headers.icode = "E7ADFCCC4B7719AF";
  // 必须返回 config
  return config;
});

// 返回拦截器 
service.interceptors.response.use(response => {
    const { success, message, data } = response.data
    if(success){
        return data
    }
    //TODO:业务请求错误
    return Promise.reject(new Error(message))
})

export default service;
